// 查找no对应分类item（分类列表）
function findItem(data, id) {
    let res
    for (let i = 0; i < data.length; i++) {

        if (data[i].id === id) {
            res = data[i]
            break
        } else {
            res = {}
        }
    }

    return res
}


// 查找no对应产品详情）
function findItemDetail(data, proId) {
    let res
    for (let i = 0; i < data.length; i++) {
        if (String(data[i].proId) === String(proId)) {
            res = data[i]
            return data[i]
        } else if (data[i].pors && data[i].pors.length > 0) {
            res = findItemDetail(data[i].pors, proId)
        }
        if (res) break
    }
    return res
}



// 分类页面渲染
function creatProType(data) {
    document.title = data.title + '_郑州品味坊食品工业有限公司'

    imglist(data.pors)
}

// 分类列表渲染
function typeList(data, index) {

    for (var i = 0; i < data.length; i++) {
        var htmls = '<li><a data-ids="' + data[i].id + '" href="productlist.html?id=' + data[i].id + '" tppabs="productlist.html?id=' + data[i].id + '">' + data[i].title + '</a></li>'
        var htmlt = '<li class="cur"><a data-ids="' + data[i].id + '" href="productlist.html?id=' + data[i].id + '" tppabs="productlist.html?id=' + data[i].id + '">' + data[i].title + '</a></li>'
        if (data[i].id == index) {
            $(".newnacs").append(htmlt)
        } else {
            $(".newnacs").append(htmls)
        }


    }
    //
}


// 渲染产品列表
function imglist(data) {
    $(".channel_main").prepend('<div class="channel_banner asdsad" style="background-image:url(' + data[0].bgimg + ');"></div>')
    for (var i = 0; i < data.length; i++) {
        var html = '<div class="span-4 smal-12 pros">' +
            '<div class="prol imghove">' +
            '<div class="_img">' +
            ' <a href="prodetails.html?proid=' + data[i].proId + '" tppabs="prodetails.html?proid=' + data[i].proId + '" target="_blank" title="' + data[i].name + '" class="rect-100"><img src="' + data[i].image + '" alt="牛油果浆"></a> ' +
            '</div>' +
            ' <a href="' + data[i].link + '" tppabs="' + data[i].link + '" target="_blank" title="' + data[i].name + '">' +
            '    <div class="fix">' +
            '    <h2 class="_title">' + data[i].name + '</h2>' +
            '    </div>' +
            '  <div class="_text"></div>' +
            ' </a>' +
            ' <div class="_btns">' +
            ' <a target="_blank" href="' + data[i].tmallink + '" tppabs=""><i class="pli pli02"></i>淘宝购买</a>' +
            '</div>' +
            '</div>' +
            '</div>'
        $('.cpro_lists').append(html)
    }
}


// 渲染产品详情
function creatData(data) {

    document.title = data.name + '_郑州品味坊食品工业有限公司'
    $(".img-bg").append('<img src="' + data.bgimg + '" />')
    $(".img-banner").append('<img src="' + data.image + '" alt="' + data.title + '" />')
    $(".pro-title").html(data.name)
    $(".tm-link").append('<a target="_blank" href="' + data.tmallink + '"><i class="pli pli02"></i>淘宝购买</a>')
    loadImg(data.imgs)

}

// 渲染产品详情图图片
function loadImg(data) {
    for (var i = 0; i < data.length; i++) {
        var src = '<img src="' + data[i] + '">'
        $('.img-conts').append(src)
    }
}

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == variable) { return pair[1]; }
    }
    return (false);
}


// 新闻列表页
function creatNewslist(data) {
    for (var i = 0; i < data.length; i++) {
        var html = ' <li class="imghove">' +
            '<div class="_img">' +
            ' <a href="newsdetails.html?year=' + data[i].id + '" tppabs="#" title="' + data[i].title + '"' +
            ' target="_blank" class="rect-75">' +
            ' <img src="' + data[i].avatar + '" alt="' + data[i].title + '">' +
            ' </a>' +
            ' </div>' +
            ' <div class="_intro">' +
            '   <a href="newsdetails.html?year=' + data[i].id + '" tppabs="#" title="' + data[i].title + '"' +
            '  target="_blank">' +
            '     <h2 class="_title"><strong>' + data[i].title + '</strong></h2>' +
            ' </a>' +
            ' <div class="_tools fix">' +
            '  <span class="lt"><i class="ion">&#xe678;</i>发布日期：' + data[i].data + '</span>' +
            '  <span class="lt" style="display:none"><i class="ion">&#xe6e2;</i>访问量：' + data[i].views + '</span>' +
            '  <span class="lt" style="display:none">' +
            '     <a href="newsdetails.html?year=' + data[i].id + '"' +
            '        class="jiathis jiathis_txt jtico jtico_jiathis"><i' +
            '          class="ion">&#xe84a;</i>分享</a>' +
            '  </span>' +
            '  </div>' +
            ' </div>' +
            ' </li>'
        $('.cratnewslist').append(html)
    }

}

function creatNewsdetails(data) {
    document.title = data.title + '_郑州品味坊食品工业有限公司'
    $(".netit").html(data.title)
    // $(".newdata").html(data.data)
    // $("#viewCountId").html(data.views)

    for (var i = 0; i < data.imgs.length; i++) {
        var src = '<p><img style="float:none;width: 100%;" src="' + data.imgs[i] + '"></p>'
        $('.news-conts').append(src)
    }
}